var express = require('express');
var router = express.Router();

const collection = require("../models/collection")

const formidable = require('formidable');

router.post('/', (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req, async function (err, fields, files) {
        if (err) {
            res.json({ 'state': false })
        } else {
            // console.log(fields.list)
            let return_data = []
            for(let i = 0; i<fields.list.length; i++){
                let doc = await collection.find({
                    UUID: fields.UUID,
                    question_ID: fields.list[i].id,
                    attachment: fields.list[i].attachment
                }, {
                    attachment: 1,
                    question_ID: 1, // point_id 
                    _id: 0
                })
                // console.log(doc, '收藏')
                if(doc.length !== 0){
                  return_data.push(true)
                } else {
                  return_data.push(false)
                }
            }
            res.json({ 'state': true, 'result': return_data })
            
        }

    });

});

module.exports = router;